package com.example.demo.leetcode;

/**
 * 链接: <a href="https://leetcode.cn/problems/determine-the-winner-of-a-bowling-game/description/">https://leetcode.cn/problems/determine-the-winner-of-a-bowling-game/description/</a>
 *
 * @author WangYX
 * @version 1.0.0
 * @date 2024/01/29 12:25
 */
public class _2660_保龄球游戏的获胜者 {

    public static void main(String[] args) {
        int[] player1 = {3, 6, 10, 8};
        int[] player2 = {9, 9, 9, 9};
        int winner = isWinner(player1, player2);
        System.out.println(winner);
    }

    public static int isWinner(int[] player1, int[] player2) {
        int n = player1.length;
        int totalScore1 = 0;
        int totalScore2 = 0;
        int doubleScore1 = 0;
        int doubleScore2 = 0;
        for (int i = 0; i < n; i++) {
            int score = player1[i];
            if (doubleScore1 >= 1) {
                totalScore1 += 2 * score;
                doubleScore1--;
            } else {
                totalScore1 += score;
            }
            if (score == 10) {
                doubleScore1 = 2;
            }

            int score2 = player2[i];
            if (doubleScore2 >= 1) {
                totalScore2 += 2 * score2;
                doubleScore2--;
            } else {
                totalScore2 += score2;
            }
            if (score2 == 10) {
                doubleScore2 = 2;
            }
        }
        return totalScore1 > totalScore2 ? 1 : totalScore1 < totalScore2 ? 2 : 0;
    }


}
